import { BasicColumn, FormSchema } from "/@/components/Table"
import { rules } from "/@/utils/helper/validator"
import { render } from "/@/utils/common/renderUtils"
import { listGroup } from "/@/api/sys/article"

export const columns: BasicColumn[] = [
  {
    title: "标题",
    width: 160,
    dataIndex: "title",
  },
  {
    title: "所属分类",
    dataIndex: "groupName",
    width: 100,
  },
  {
    title: "状态",
    dataIndex: "status",
    width: 60,
    customRender: ({ text }) => {
      const color = text == "2" ? "red" : text == "1" ? "green" : "gray"
      return render.renderTag(render.renderDict(text, "article_status"), color)
    },
  },
  {
    title: "排序",
    width: 50,
    dataIndex: "sortNo",
  },
  {
    title: "标识",
    width: 160,
    dataIndex: "code",
  },
  {
    title: "创建者",
    width: 100,
    dataIndex: "createdBy",
  },
  {
    title: "创建时间",
    width: 160,
    dataIndex: "createdAt",
  },
  {
    title: "更新时间",
    width: 160,
    dataIndex: "updatedAt",
  },
]

export const searchFormSchema: FormSchema[] = [
  {
    field: "title",
    label: "标题",
    component: "Input",
  },
  {
    field: "code",
    label: "标识",
    component: "Input",
  },
  {
    field: "groupId",
    label: "文章组",
    component: "ApiSelect",
  },
]

export const formSchema: FormSchema[] = [
  {
    field: "id",
    label: "id",
    component: "Input",
    show: false,
  },
  {
    label: "文章组",
    field: "groupId",
    component: "ApiSelect",
    componentProps: {
      optionFilterProp: "label",
      labelField: "name",
      valueField: "id",
      showSearch: true,
      api: listGroup,
    },
    colProps: {
      // span: '24',
      // style: {
      //   width: '30%'
      // }
    },
  },
  {
    field: "title",
    label: "标题",
    component: "Input",
    required: true,
    componentProps: {
      placeholder: "请输入标题",
    },
  },
  {
    field: "code",
    label: "标识",
    component: "Input",
    required: false,
    componentProps: {
      placeholder: "请输入标识",
    },
  },
  {
    field: "remark",
    label: "摘要",
    component: "InputTextArea",
  },
  {
    field: "content",
    label: "内容",
    component: "MyRichTextEditor",
  },
  {
    field: "attachments",
    label: "上传附件",
    component: "MyUpload",
    defaultValue: [],
    valueType: "array",
    componentProps: ({ formModel, formActionType }) => {
      return {
        returnUrl: false,
        bizType: "articleAttachment",
        maxCount: 5,
        containerWidth: "50%",
        jsonFilePathKey: "url",
        jsonFileNameKey: "name",
        jsonFileSizeKey: "size",
      }
    },
  },
  {
    field: "visitVirtual",
    label: "虚拟访问量",
    component: "InputNumber",
    componentProps: {
      size: "middle",
      style: {
        width: "20%",
      },
    },
  },
  {
    field: "sortNo",
    label: "排序",
    component: "InputNumber",
    componentProps: {
      size: "middle",
      style: {
        width: "20%",
      },
    },
  },
  {
    field: "status",
    label: "状态",
    required: true,
    component: "JDictSelectTag",
    defaultValue: "1",
    componentProps: {
      type: "radio",
      dictType: "article_status",
    },
  },
]
